package com.leijie.netty;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.time.LocalDateTime;

/**
 * @author LeiJie
 * @time 2020-5-13 16:30
 * @desc TODO
 */
public class ClientHandle extends SimpleChannelInboundHandler<String> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
        System.out.println("服务端消息："+msg);
        Thread.sleep(1000);
        ctx.writeAndFlush(LocalDateTime.now().toString());
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        //客户端建立链接之后 发送当前时间
        ctx.writeAndFlush("登录消息："+LocalDateTime.now());
    }
}
